package cn.hdu.liang.holding;

import java.util.*;

public class MultiIterableClass extends IterableClass {

    public Iterable<String> reversed() {
        return () -> new Iterator<String>() {
            public int current = words.length - 1;

            @Override
            public boolean hasNext() {
                return current > -1;
            }

            @Override
            public String next() {
                return words[current--];
            }
        };
    }

    public Iterable<String> randomized() {
        return () -> {
            List<String> shuffled = new ArrayList<>(Arrays.asList(words));
            Collections.shuffle(shuffled, new Random(47));
            return shuffled.iterator();
        };
    }

    public static void main(String[] args) {
        MultiIterableClass mic = new MultiIterableClass();

        //正向遍历
        for(String s : mic) {
            System.out.print(s + " ");
        }
        System.out.println();

        //反向遍历
        for(String s : mic.reversed()) {
            System.out.print(s + " ");
        }
        System.out.println();

        //随机遍历
        for(String s : mic.randomized()) {
            System.out.print(s + " ");
        }
        System.out.println();
    }
}
